Skip to content

Add OptionalFilterPhysicalExpr wrapper + proto support#22234

Draft
adriangb wants to merge 1 commit into
apache:mainfrom
adriangb:pr1-optional-filter-physical-expr
Draft

Add OptionalFilterPhysicalExpr wrapper + proto support#22234
adriangb wants to merge 1 commit into
apache:mainfrom
adriangb:pr1-optional-filter-physical-expr

Conversation

@adriangb
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Adaptive filter scheduling needs a way to mark a PhysicalExpr as a performance hint — a filter that may be dropped without affecting query correctness (e.g. a hash-join dynamic filter, whose predicate the join already enforces). This PR adds that marker type. It is deliberately inert: nothing reads it yet.

What changes are included in this PR?

  • OptionalFilterPhysicalExpr: a transparent PhysicalExpr wrapper that delegates every trait method to its inner expression.
  • Proto support: a new PhysicalOptionalFilterNode message so physical plans containing the wrapper round-trip through datafusion-proto.

No caller wraps anything yet — the hash-join wrap and the parquet scheduler that consume the marker arrive later in the stack.

Are these changes tested?

Yes — unit tests for the wrapper's delegation behavior and a proto round-trip test.

Are there any user-facing changes?

New public type OptionalFilterPhysicalExpr. Purely additive; no behavior change.


Stacked PRs (review/merge in order):

  1. this PR — OptionalFilterPhysicalExpr + proto
  2. Per-conjunct pruning statistics
  3. SelectivityTracker cost model
  4. Adaptive parquet scan integration

Introduce `OptionalFilterPhysicalExpr`, a transparent `PhysicalExpr`
wrapper that marks a filter as *optional* — droppable without affecting
query correctness. It delegates every `PhysicalExpr` method to the inner
expression, so it is behavior-neutral until a consumer explicitly checks
for the marker.

This is the foundation for adaptive filter scheduling: a scan can detect
the wrapper and drop a performance-hint filter (e.g. a hash-join dynamic
filter) when it is not cost-effective, knowing correctness is enforced
elsewhere.

Also adds proto serialization (`PhysicalOptionalFilterNode`) so physical
plans containing the wrapper round-trip faithfully.

No caller wraps anything yet — that arrives with the adaptive parquet
scan later in the stack.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Thank you for opening this pull request!

Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch).

Details
     Cloning apache/main
    Building datafusion-physical-expr-common v53.1.0 (current)
       Built [  28.811s] (current)
     Parsing datafusion-physical-expr-common v53.1.0 (current)
      Parsed [   0.022s] (current)
    Building datafusion-physical-expr-common v53.1.0 (baseline)
       Built [  18.807s] (baseline)
     Parsing datafusion-physical-expr-common v53.1.0 (baseline)
      Parsed [   0.022s] (baseline)
    Checking datafusion-physical-expr-common v53.1.0 -> v53.1.0 (no change; assume patch)
     Checked [   0.278s] 222 checks: 222 pass, 30 skip
     Summary no semver update required
    Finished [  49.155s] datafusion-physical-expr-common
    Building datafusion-proto v53.1.0 (current)
       Built [  52.143s] (current)
     Parsing datafusion-proto v53.1.0 (current)
      Parsed [   0.140s] (current)
    Building datafusion-proto v53.1.0 (baseline)
       Built [  52.274s] (baseline)
     Parsing datafusion-proto v53.1.0 (baseline)
      Parsed [   0.138s] (baseline)
    Checking datafusion-proto v53.1.0 -> v53.1.0 (no change; assume patch)
     Checked [   2.245s] 222 checks: 221 pass, 1 fail, 0 warn, 30 skip

--- failure enum_variant_added: enum variant added on exhaustive enum ---

Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/enum_variant_added.ron

Failed in:
  variant ExprType:OptionalFilter in /home/runner/work/datafusion/datafusion/datafusion/proto/src/generated/prost.rs:1397
  variant ExprType:OptionalFilter in /home/runner/work/datafusion/datafusion/datafusion/proto/src/generated/prost.rs:1397

     Summary semver requires new major version: 1 major and 0 minor checks failed
    Finished [ 109.275s] datafusion-proto

@github-actions github-actions Bot added the auto detected api change Auto detected API change label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto detected api change Auto detected API change physical-expr Changes to the physical-expr crates proto Related to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant